package thread;
public class OrderedPrinting {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Object locker3 = new Object();

        Thread C = new Thread(()->{
            try{
                synchronized (locker1){
                    locker1.wait();

                }
                System.out.println('C');
                synchronized (locker2){
                    locker2.notify();
                }
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        Thread B = new Thread(()->{
            try{
                synchronized (locker2){
                    locker2.wait();
                }
                System.out.println('B');
                synchronized (locker3){
                    locker3.notify();
                }
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        Thread A = new Thread(()->{
            try{
                synchronized (locker3){
                    locker3.wait();
                }
                System.out.println('A');
                synchronized (locker1){
                    locker1.notify();
                }
            }catch (InterruptedException e){
                throw new RuntimeException();
            }
        });

        C.start();
        B.start();
        A.start();

        Thread.sleep(1000);
        synchronized (locker1) {
            locker1.notify();
        }
    }
}
